using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

namespace FederationMembershipDB
{
	public class RegistrationFee
	{
		double _amountPaid;
		DateTime _datePaid;		
		bool _questionnaireCompleted;
		bool _contractCompleted;
		TransactionDetails _paymentHistory;

        public RegistrationFee(double FeeAmount, DateTime DatePaid, bool QuestionnaireCompleted, bool ContractCompleted)
        {
            _amountPaid = FeeAmount;
            _datePaid = DatePaid;
            _questionnaireCompleted = QuestionnaireCompleted;
            _contractCompleted = ContractCompleted;
        }
        public double FeeAmount
        { get { return _amountPaid; } set { _amountPaid = value; } }
        
        public DateTime DatePaid
        { get { return _datePaid; } set { _datePaid = value; } }

        public bool QuestionnaireCompleted
        { get { return _questionnaireCompleted; } set { _questionnaireCompleted = value; } }

        public bool ContractedCompleted
        { get { return _contractCompleted; } set { _contractCompleted = value; } }


		public void MakePayment(ref int RegFeeID)
		{
            //Parameter: ref int ChequeID - when cheque ID is set, the int variable passed in will be updated in the calling function

            //           SqlTransaction - to keep the transaction as a whole unit, pass in an existing Transaction

            //Get the last ID in the DB
            string sqlSelectID = "SELECT TOP(1) ID FROM RegistrationFee Order By ID DESC;";
            DataSet ds = Utilities.SearchDatabase(sqlSelectID);

            //check to see if it will be the first item inserted.
            if (ds.Tables[0].Rows.Count == 0)
            {
                RegFeeID = 0;
            }
            else
            {
                RegFeeID = int.Parse(ds.Tables[0].Rows[0].ItemArray.GetValue(0).ToString()) + 1; // +1 to increment - the next chequeID
            }

            //Construct INSERT statement
            string sqlInsert = "INSERT INTO RegistrationFee VALUES ('" + RegFeeID + "','" + FeeAmount + "', CONVERT(datetime, '" + DatePaid + "', 103), '" + QuestionnaireCompleted + "','" + ContractedCompleted + "');";

            Utilities.DatabaseNonQuery(sqlInsert);

		}

	}
}
